﻿@page "/tree-grid/clipboard"

@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.TreeGrid
@using Syncfusion.Blazor.Navigations
@*Hidden:Lines*@
@using ej2_blazor_selfdata
@inherits SampleBaseComponent;
@*End:Hidden*@

@{
    List<ItemModel> Toolbar = new List<ItemModel>();
    Toolbar.Add(new ItemModel { Text = "Copy", TooltipText = "Copy", PrefixIcon = "e-copy", Id = "copy" });
    Toolbar.Add(new ItemModel { Text = "Copy With Header", TooltipText = "Copy With Header", PrefixIcon = "e-copy", Id = "copyHeader" });
}

<SampleDescription>
    <p>This sample demonstrates copy to clipboard functionality of the Tree Grid component. Select rows and click Copy button from toolbar to copy content. To copy with header click Copy with header button from toolbar. </p>
</SampleDescription>
<ActionDescription>
    <p>Selected row or cell data in the Tree Grid can be copied into the clipboard using the Keyboard shortcuts and <code><a target='_blank' class='code' href='https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.TreeGrid.SfTreeGrid-1.html#Syncfusion_Blazor_TreeGrid_SfTreeGrid_1_Copy_System_Nullable_System_Boolean__'>Copy</a></code> method.</p>
    <p>In this demo, selected rows data can be copied into the clipboard using the below Keyboard shortcuts or toolbar interactions.</p>
    <ul><li><code>Ctrl + C</code> - Selected rows or cells data without header.</li>
         <li><code>Ctrl + Shift + H</code> - Selected rows or cells data with header.</li>
    </ul>
    <p>More information on the clipboard can be found in this <a target='_blank' href='https://blazor.syncfusion.com/documentation/treegrid/clipboard/'>documentation section</a>.</p>
</ActionDescription>

<div class="col-lg-12 control-section">
    <div class="content-wrapper">
        <div class="row">
             <SfTreeGrid @ref="@TreeGrid" Toolbar="Toolbar" Height="315" DataSource="@TreeData" IdMapping="TaskID" AllowPaging="true" ParentIdMapping="ParentID" TreeColumnIndex="1">
                <TreeGridEvents TValue="SelfReferenceData" OnToolbarClick="ToolbarClick"></TreeGridEvents>
                <TreeGridSelectionSettings Type="SelectionType.Multiple"></TreeGridSelectionSettings>
                <TreeGridPageSettings PageSize="2"></TreeGridPageSettings>
                <TreeGridColumns>
                    <TreeGridColumn Field="TaskID" HeaderText="Task ID" Width="80" TextAlign="TextAlign.Right"></TreeGridColumn>
                    <TreeGridColumn Field="TaskName" HeaderText="Task Name" Width="145"></TreeGridColumn>
                    <TreeGridColumn Field="StartDate" HeaderText="Start Date" Format="d" Type=ColumnType.Date Width="88" TextAlign="TextAlign.Right"></TreeGridColumn>
                    <TreeGridColumn Field="Duration" HeaderText="Duration" Width="100" TextAlign="TextAlign.Right"></TreeGridColumn>
                    <TreeGridColumn Field="Progress" HeaderText="Progress" Width="100"></TreeGridColumn>
                    <TreeGridColumn Field="Priority" HeaderText="Priority" Width="100"></TreeGridColumn>

                </TreeGridColumns>
            </SfTreeGrid>
        </div>
    </div>
</div>

@code{
    SfTreeGrid<SelfReferenceData> TreeGrid;

    public List<SelfReferenceData> TreeData { get; set; }

    protected override void OnInitialized()
    {
        this.TreeData = SelfReferenceData.GetTree().ToList();
    }

    public async void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs Args)
    {
        var SelectedRecords = await this.TreeGrid.GetSelectedRecords();
        if (SelectedRecords.Count() > 0)
        {
            var WithHeader = false;
            if (Args.Item.Id == "copyHeader")
            {
                WithHeader = true;
            }
            await this.TreeGrid.CopyAsync(WithHeader);
        }
    }
}
